var o, e = require, t = module, n = exports, i = this && this.__extends || (o = function(t, e) {
    return (o = Object.setPrototypeOf || {
        __proto__: []
    } instanceof Array && function(t, e) {
        t.__proto__ = e;
    } || function(t, e) {
        for (var n in e) e.hasOwnProperty(n) && (t[n] = e[n]);
    })(t, e);
}, function(t, e) {
    function n() {
        this.constructor = t;
    }
    o(t, e), t.prototype = null === e ? Object.create(e) : (n.prototype = e.prototype, 
    new n());
}), a = this && this.__decorate || function(t, e, n, o) {
    var s, i = arguments.length, a = i < 3 ? e : null === o ? o = Object.getOwnPropertyDescriptor(e, n) : o;
    if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) a = Reflect.decorate(t, e, n, o); else for (var l = t.length - 1; 0 <= l; l--) (s = t[l]) && (a = (i < 3 ? s(a) : 3 < i ? s(e, n, a) : s(e, n)) || a);
    return 3 < i && a && Object.defineProperty(e, n, a), a;
};

Object.defineProperty(n, "__esModule", {
    value: !0
});

var r = e("Global"), s = e("PlayerModel"), c = e("PetShow"), l = e("PetManager"), d = e("GameConfig"), u = e("GameData"), p = e("EquipManager"), h = e("LoadManager"), f = cc._decorator, g = f.ccclass, m = f.property, y = function(e) {
    function t() {
        var t = null !== e && e.apply(this, arguments) || this;
        return t.skeleton = null, t.sprite = null, t.show = null, t.slot = null, t.personIdx = null, 
        t.gunIdx = null, t.petIdx = null, t.backEquipIdx = null, t.headEquipIdx = null, 
        t;
    }
    return i(t, e), t.prototype.start = function() {}, t.prototype.init = function(t, e, n, o, s) {
        var i = this;
        void 0 === t && (t = u.GD.personIdx), void 0 === e && (e = u.GD.gunIdx), void 0 === n && (n = u.GD.backEquipIdx), 
        void 0 === o && (o = u.GD.headEquipIdx), null == t && (t = u.GD.personIdx), null == e && (e = u.GD.gunIdx), 
        this.personIdx != t ? ((this.personIdx = t) < 0 ? this.loadEggPerson(r.G.getEggIdx(t, 2)) : this.loadPerson(t)).then(function() {
            i.changeGun(e), i.doEquip(t, n, o), s && s();
        }) : (this.changeGun(e), this.doEquip(t, n, o), s && s());
    }, t.prototype.initPet = function(t, e) {
        var n = this;
        void 0 === t && (t = l.default.getInstance().getPetIdx()), -1 < r.G.tryPetIdx && Math.floor(t / 100) == Math.floor(r.G.tryPetIdx / 100) && (t = r.G.tryPetIdx), 
        this.petIdx != t ? (this.petIdx = t, this.loadPet(t).then(function() {
            n.show && n.show.refresh(), e && e();
        })) : (this.show && this.show.refresh(), e && e());
    }, t.prototype.initEquip = function(t, e) {
        -1 < t && (1 == e ? (this.backEquipIdx = t, this.init(this.personIdx, this.gunIdx, this.backEquipIdx, u.GD.headEquipIdx)) : 2 == e && (this.headEquipIdx = t, 
        this.init(this.personIdx, this.gunIdx, u.GD.backEquipIdx, this.headEquipIdx)));
    }, t.prototype.doEquip = function(e, t, n) {
        var o, s, i = this;
        if (void 0 === e && (e = this.personIdx), void 0 === t && (t = this.backEquipIdx), 
        void 0 === n && (n = this.headEquipIdx), this.skeleton) try {
            -1 < t ? (o = p.default.getInstance().getConfig(t), s = p.default.getInstance().getData(t), 
            o.list[s.form].forEach(function(t) {
                [ 17, 18, 19, 20, 21, 22, 116, -17 ].includes(e) ? i.skeleton.findSlot(t.slot) && i.skeleton.setAttachment(t.slot, t.attachment) : i.skeleton.findSlot(t.slot) && i.skeleton.setAttachment(t.slot, t.attachment && (e < 105 && -1 < e || 112 == e || -16 == e) ? "ren/" + t.attachment : t.attachment);
            })) : (this.skeleton.findSlot("zuo") && this.skeleton.setAttachment("zuo", null), 
            this.skeleton.findSlot("you") && this.skeleton.setAttachment("you", null)), -1 < n ? (o = p.default.getInstance().getConfig(n), 
            s = p.default.getInstance().getData(n), o.list[s.form].forEach(function(t) {
                [ 17, 18, 19, 20, 21, 22, 116, -17 ].includes(e) ? "jiaozuo" == t.slot ? i.skeleton.findSlot("zuojijiao") && i.skeleton.setAttachment("zuojijiao", t.attachment) : "jiaoyou" == t.slot ? i.skeleton.findSlot("youjijiao") && i.skeleton.setAttachment("youjijiao", t.attachment) : i.skeleton.findSlot(t.slot) && i.skeleton.setAttachment(t.slot, t.attachment) : i.skeleton.setAttachment(t.slot, t.attachment && (e < 105 && -1 < e || 112 == e || -16 == e) ? "ren/" + t.attachment : t.attachment);
            })) : ([ 17, 18, 19, 20, 21, 22, 116, -17 ].includes(e) ? (this.skeleton.setAttachment("zuojijiao", null), 
            this.skeleton.setAttachment("youjijiao", null)) : (this.skeleton.setAttachment("jiaozuo", null), 
            this.skeleton.setAttachment("jiaoyou", null)), this.skeleton.setAttachment("guanghuan", null));
        } catch (t) {
            cc.error(t);
        }
    }, t.prototype.changeGun = function(t) {
        var e, n = this;
        this.sprite && (e = r.G.getGunModel(t), this.skeleton && e && (this.slot = this.skeleton.findSlot(e.slot), 
        this.gunIdx != t && ((3e3 <= (this.gunIdx = t) ? this.loadOlympicGun(t) : 2e3 <= t ? this.loadDrawGun(t - 2e3) : 1e3 <= t ? this.loadEggGun(t - 1e3) : t < 0 ? this.loadEggGun(r.G.getEggIdx(t)) : this.loadGun(t)).then(function() {
            n.adjustGunAnchor(e);
        }), this.sprite.node.angle = 1008 == t ? 0 : 33)));
    }, t.prototype.adjustGunAnchor = function(t) {
        this.sprite && t && ("shouqiang" == t.slot ? (this.sprite.node.anchorX = .65, this.sprite.node.anchorY = .4, 
        this.sprite.node.angle = 52 * this.sprite.node.scaleX) : "changqiang" == t.slot ? (t.type == s.ArmType.狙击枪 ? this.sprite.node.anchorX = .7 : (t.type == s.ArmType.导弹枪 || t.type == s.ArmType.激光枪 || (t.type, 
        s.ArmType.冰冻枪), this.sprite.node.anchorX = .62), this.sprite.node.anchorY = .37, 
        this.sprite.node.angle = 33 * this.sprite.node.scaleX) : (this.sprite.node.anchorX = .5, 
        this.sprite.node.anchorY = .5));
    }, t.prototype.loadPerson = function(n) {
        var o = this;
        return new Promise(function(e, t) {
            r.G.personModelList.every(function(t) {
                return t.id != n;
            }) && (n = u.GD.lastPersonIdx), h.default.getInstance().loadRes({
                url: "skin/" + n + "/skeleton",
                type: sp.SkeletonData
            }).then(function(t) {
                o.skeleton && t instanceof sp.SkeletonData && (o.skeleton.skeletonData = t, o.skeleton.setAnimation(0, "animation3", !0)), 
                e();
            }).catch(function() {
                t();
            });
        });
    }, t.prototype.loadGun = function(n) {
        var o = this;
        return cc.log("PersonView loadGun", n), new Promise(function(t, e) {
            h.default.getInstance().loadSpriteFrame({
                url: "image/arm/" + n,
                sprite: o.sprite,
                success: function() {
                    o.sprite.node.scaleX = o.skeleton.node.scaleX, o.sprite.node.scaleY = o.skeleton.node.scaleY, 
                    t();
                },
                fail: function() {
                    e();
                }
            });
        });
    }, t.prototype.loadPet = function(o) {
        var s = this;
        return new Promise(function(e, t) {
            var n = Math.round(o / 100);
            o = 0 < d.GC.petModelList.length && 0 <= n && n < d.GC.petModelList.length ? d.GC.petModelList[n].id + Math.min(o % 100, d.GC.petModelList[n].form) : n = 0, 
            s.petIdx = o, h.default.getInstance().loadRes({
                url: "skin/p" + o + "/" + l.default.getInstance().getSkinConfig(n).suf,
                type: sp.SkeletonData
            }).then(function(t) {
                s.skeleton && t instanceof sp.SkeletonData && (s.skeleton.skeletonData = t, s.skeleton.setAnimation(0, "move2", !0)), 
                e();
            }).catch(function() {
                t();
            });
        });
    }, t.prototype.loadEggPerson = function(n) {
        var o = this;
        return new Promise(function(e, t) {
            r.G.eggPersonModelList.every(function(t) {
                return t.id != n;
            }) && (n = 0), h.default.getInstance().loadRes({
                url: "skin/" + (n + 100) + "/skeleton",
                type: sp.SkeletonData
            }).then(function(t) {
                o.skeleton && t instanceof sp.SkeletonData && (o.skeleton.skeletonData = t, o.skeleton.setAnimation(0, "animation3", !0)), 
                e();
            }).catch(function() {
                t();
            });
        });
    }, t.prototype.loadEggGun = function(n) {
        var o = this;
        return n < 0 || 0 == r.G.eggGunModelList.length ? n = 0 : n >= r.G.eggGunModelList.length && (n = r.G.eggGunModelList.length - 1), 
        new Promise(function(t, e) {
            h.default.getInstance().loadSpriteFrame({
                url: "image/arm3/" + n,
                sprite: o.sprite,
                success: function() {
                    o.sprite.node.scaleX = o.skeleton.node.scaleX, o.sprite.node.scaleY = o.skeleton.node.scaleY, 
                    t();
                },
                fail: function() {
                    e();
                }
            });
        });
    }, t.prototype.loadDrawGun = function(n) {
        var o = this;
        return new Promise(function(t, e) {
            h.default.getInstance().loadSpriteFrame({
                url: "image/arm_draw/" + n,
                sprite: o.sprite,
                success: function() {
                    o.sprite.node.scaleX = o.skeleton.node.scaleX, o.sprite.node.scaleY = o.skeleton.node.scaleY, 
                    t();
                },
                fail: function() {
                    e();
                }
            });
        });
    }, t.prototype.loadOlympicGun = function(n) {
        var o = this;
        return new Promise(function(t, e) {
            h.default.getInstance().loadSpriteFrame({
                url: "texture/armOlympic/" + n,
                sprite: o.sprite,
                success: function() {
                    o.sprite.node.scaleX = o.skeleton.node.scaleX, o.sprite.node.scaleY = o.skeleton.node.scaleY, 
                    t();
                },
                fail: function() {
                    e();
                }
            });
        });
    }, t.prototype.updateBySlot = function(t) {
        t && this.slot && this.slot.bone && 0 != this.slot.bone.worldX && 0 != this.slot.bone.worldY && (t.active || (t.active = !0), 
        t.setPosition(cc.v2(this.slot.bone.worldX * this.skeleton.node.scaleX, (this.slot.bone.worldY + this.skeleton.node.y) * this.skeleton.node.scaleY)));
    }, t.prototype.update = function() {
        this.sprite && this.updateBySlot(this.sprite.node);
    }, a([ m(sp.Skeleton) ], t.prototype, "skeleton", void 0), a([ m(cc.Sprite) ], t.prototype, "sprite", void 0), 
    a([ m(c.default) ], t.prototype, "show", void 0), a([ g ], t);
}(cc.Component);

n.default = y;